<?php
/*
    Copyright (C) 2008 - 2009 Inanta Martsanto
    
    This file is part of Koma.

    Koma is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Koma is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Koma.  If not, see <http://www.gnu.org/licenses/>.
    
    Inanta Martsanto (inanta@inationsoft.co.cc)
*/

function show_message($messageheader, $message = '')
{
    try
    {
        $mapper = KomaClassMapper::getInstance();
        if ($mapper->getClassPath('KomaTemplate')) include_once($mapper->getClassPath('KomaTemplate'));
    }
    catch(Exception $e)
    {
        include_once('../classes/template/KomaTemplate.class.php');
    }
    
    if(!defined('KOMA_THEME_PATH')) define('KOMA_THEME_PATH', KOMA_ROOT_PATH.'/themes');
    if(!defined('KOMA_THEME')) define('KOMA_THEME', 'basic');
    
    if(ob_get_contents()) ob_end_clean();

    if(!class_exists('KomaTemplate') || !file_exists(KOMA_THEME_PATH.'/'.KOMA_THEME.'/site_message.html'))
	exit('<html><head><title>'.
	(defined('KOMA_SITE_TITLE') ? KOMA_SITE_TITLE : KOMA_DEFAULT_SITE_TITLE) . ' - ' .
        (defined('KOMA_SITE_SLOGAN') ? KOMA_SITE_SLOGAN : KOMA_DEFAULT_SITE_SLOGAN).'</title></head><body><h2>'.$messageheader.'</h2><h3>'.$message.'</h3><body></html>');
    
    $komaTpl = KomaTemplate::getInstance();
    $komaTpl->clear_all_assign();
    $komaTpl->assign('title', (defined('KOMA_SITE_TITLE') ? KOMA_SITE_TITLE : KOMA_DEFAULT_SITE_TITLE) . ' - ' .
                     (defined('KOMA_SITE_SLOGAN') ? KOMA_SITE_SLOGAN : KOMA_DEFAULT_SITE_SLOGAN));
    
    $meta = array();
    $meta['keyword'] = defined('KOMA_META_KEY') ? KOMA_META_KEY : KOMA_DEFAULT_META_KEY;
    $meta['description'] = defined('KOMA_META_DESC') ? KOMA_META_DESC : KOMA_DEFAULT_META_DESC;
    $meta['author'] = defined('KOMA_META_AUTHOR') ? KOMA_META_AUTHOR : KOMA_DEFAULT_META_AUTHOR;
    $meta['copyright'] = defined('KOMA_META_COPYRIGHT') ? KOMA_META_COPYRIGHT : KOMA_DEFAULT_META_COPYRIGHT;
    $meta['generator'] = defined('KOMA_META_GENERATOR') ? KOMA_META_GENERATOR : KOMA_DEFAULT_META_GENERATOR;
    
    $komaTpl->assign('meta', $meta);

    $komaStyleManager = KomaStyleManager::getInstance();
    
    $komaStyleManager->addSource(KOMA_ROOT_PATH.'/scripts/css/ui-lightness/jquery-ui-1.7.2.custom.css');
    $komaStyleManager->addSource(KOMA_ROOT_PATH.'/themes/'.KOMA_THEME.'/widgets.css');
    $komaStyleManager->addSource(KOMA_ROOT_PATH.'/themes/'.KOMA_THEME.'/theme.css');
    
    $_SESSION['CSSSources'] = $komaStyleManager->getSources();
    $_SESSION['CSSStyle'] = $komaStyleManager->getStyles();

    $komaTpl->assign('stylemanager', '<link rel="stylesheet" type="text/css" href="'.KOMA_URL.'/cssaggregator.php/'.md5(serialize($komaStyleManager)).'"></link>');

    $komaTpl->assign('favicon', KOMA_DEFAULT_FAVICON);
    
    if(!defined('KOMA_THEME')) define('KOMA_THEME', 'basic');
	
    $komaTpl->assign('time', -1);
    $komaTpl->assign('url', KOMA_URL);
    $komaTpl->assign('message_header', $messageheader);
    $komaTpl->assign('message', $message);
    $komaTpl->assign('language_menu', new KomaWidgetLanguageMenu());
    $komaTpl->assign('koma_themes_url', KOMA_URL.'/themes/'.KOMA_THEME);
    $komaTpl->display(KOMA_THEME.'/site_message.html');

    exit();
}
?>